package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func main() {
	r := gin.Default()
	//设置文件上传大小，默认32MB
	r.MaxMultipartMemory = 64 << 20 //64MB

	//加载html模板
	r.LoadHTMLFiles("cp8/gin/upload.html")
	//设置html模板的路径
	r.GET("/html", func(c *gin.Context) { //http://localhost:8086/html
		c.HTML(200, "upload.html", "flysnow_org")
	})
	//设置上传路径
	r.POST("/upload", func(c *gin.Context) {
		//file是表单字段名
		file, _ := c.FormFile("file")
		log.Println(file.Filename) //文件名
		//将上传文件保存到./data/下
		c.SaveUploadedFile(file, fmt.Sprintf("cp8/gin/data/%s", file.Filename))
		c.String(http.StatusOK, fmt.Sprintf("'%s' 上传完成", file.Filename))
	})
	r.Run(":8086")
}
